package com.lagou.edu.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class InfoDao {
    @Autowired
    private ApplicationContext context;

    /**
     * 连接数据库，获取当前时间
     * @return
     */
    public String getNow() {
        JdbcTemplate jdbcTemplate = context.getBean("zkJdbcTemplate", JdbcTemplate.class);
        Map<String, Object> result = jdbcTemplate.queryForMap("select now() as now");
        Object now = result.get("now");
        return now.toString();
    }
}
